﻿// News Framework
// (C) Tanzim Saqib. Oct 25, 2010.
// http://TanzimSaqib.com | http://newsfx.codeplex.com

namespace TanzimSaqib.NewsFramework
{
    using System;

    public sealed class Check
    {
        public static void Null(object obj)
        {
            Null(string.Empty, obj);
        }

        public static void Null(string paramName, object obj)
        {
            if (string.IsNullOrEmpty(paramName))
                paramName = obj.GetType().ToString();

            if (obj == null || (obj is string && string.IsNullOrEmpty(obj as string)))
                throw new ArgumentNullException(FxConstants.CheckNotNull.FormatWith(paramName));
        }

        public static void If(bool condition, Action onSuccess)
        {
            if (condition)
                onSuccess();
        }

        public static void If(bool condition, Action onSuccess, Action onFailure)
        {
            if (condition)
                onSuccess();
            else
                onFailure();
        }

        public static void IfNot(bool condition, Action action)
        {
            if(!condition)
                action();
        }
    }
}
